/* function combineNumber(a: number, b: number): number { 
  return a * b;
}

function combineString(a: string, b: string): string { 
  return a + b;
} */

function combine(a: number, b: number): number;
function combine(a: string, b: string): string;
function combine(a: number | string, b: number | string) { 
  if(typeof a === 'number' && typeof b === 'number') {
    return a * b;
  }
  else if(typeof a === 'string' && typeof b === 'string') {
    return a + b;
  }
  throw new Error("两个参数类型不一致");
}

const result = combine("a","b");
console.log(result);

function changeType(x: string): number;
function changeType(x: number): string;
function changeType(x: string | number): number | string { 
  return typeof x === 'string' ? parseInt(x, 10) : x.toString();
}
changeType("123")



function createElement(tag: 'a'): HTMLAnchorElement;
function createElement(tag: 'canvas'): HTMLCanvasElement;
function createElement(tag: 'table'): HTMLTableElement;
function createElement(tag: string): HTMLElement;
function createElement(tag: string): HTMLElement{ 
  return document.createElement(tag);
}

const a = createElement("a");